﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.IO;

namespace Catalyst.Web.DynamicData.Design
{
    public class DynamicFilterRepeaterDesigner : DynamicFilterContainerBaseDesigner
    {
        public DynamicFilterRepeater FilterRepeater
        {
            get { return (DynamicFilterRepeater)Component; }
        }
        
        public override string GetDesignTimeHtml()
        {
            try
            {
                Repeater repeater = new Repeater();
                repeater.HeaderTemplate = FilterRepeater.HeaderTemplate;
                repeater.ItemTemplate = FilterRepeater.ItemTemplate;
                repeater.FooterTemplate = FilterRepeater.FooterTemplate;
                repeater.DataSource = new List<object>() { 0, 1, 2, 3, 4 };
                repeater.DataBind();
                StringBuilder sb = new StringBuilder();
                using (HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb)))
                {
                    repeater.RenderControl(writer);
                    return sb.ToString();
                }
            }
            catch (Exception ex)
            {
                return base.GetErrorDesignTimeHtml(ex);
            }
        }

    }
}
